Skip to content

fix: stderr/output hygiene rollup#525

Merged
jpoehnelt merged 6 commits intomainfrom
fix/stderr-output-hygiene
Mar 17, 2026
Merged

fix: stderr/output hygiene rollup#525
jpoehnelt merged 6 commits intomainfrom
fix/stderr-output-hygiene

Conversation

@jpoehnelt
Copy link
Member

@jpoehnelt jpoehnelt commented Mar 17, 2026

Summary

Consolidates #485, #466, and #446 into a single rollup and adds codebase-wide terminal sanitization to prevent escape sequence injection through error messages.


Component 1 — Route diagnostics to stderr (#485)

  • triage.rs: println!eprintln! via extracted no_messages_msg() helper
  • modelarmor.rs: response body printed only after success check; error message now includes response body

Component 2 — Colored error labels (#466)

  • error.rs: error[api]:, error[auth]:, etc. printed to stderr in bold color on TTY
  • Respects NO_COLOR env var (de-facto standard)
  • hint: prefix replaces emoji for accessNotConfigured guidance
  • Deduplicated output: specialized hint replaces generic summary (not both)

Component 3 — Auth error propagation (#446)

  • calendar, chat, docs, drive, script, sheets: auth failures propagate as GwsError::Auth instead of silently proceeding with AuthMethod::None
  • --dry-run bypass preserved

Component 4 — Terminal sanitization helper

  • error.rs: new sanitize_for_terminal() function strips ANSI escape sequences and control characters (preserving \n/\t) before printing to stderr
  • Applied to print_error_json to prevent escape sequence injection via API error responses
  • Removed misleading test_error_path_message_includes_status_and_body test from modelarmor.rs (only tested format!(), not actual behavior)

Component 5 — Codebase-wide sanitization (16 sites across 9 files)

Every eprintln! that prints an unsanitized error string now wraps it with sanitize_for_terminal():

File Sites What gets sanitized
workflows.rs 4 Calendar/tasks/email fetch errors
watch.rs 2 Model Armor + file write errors
gmail/mod.rs 3 UTF-8, base64, date parsing errors
executor.rs 1 Model Armor sanitization error
subscribe.rs 1 File write error
token_storage.rs 2 UTF-8 + JSON parse errors
credential_store.rs 2 Permissions + keyring errors
setup.rs 1 API enable failure messages
generate_skills.rs 1 Discovery doc fetch error

Also fixes clippy: map_errinspect_err in workflows.rs where closures only log and return the error unchanged.

Tests

  • test_sanitize_for_terminal_strips_control_chars — verifies ANSI codes and control chars are stripped, \n/\t preserved
  • test_colorize_respects_no_color_env — verifies NO_COLOR disables ANSI codes
  • test_error_label_contains_variant_name — verifies each variant renders correctly
  • empty_result_message_is_not_json — verifies diagnostic is not valid JSON
  • 665 total tests pass, clippy and fmt clean

Closes #485, closes #466, closes #446

…bels, auth propagation

Component 1 (PR #485): Route triage 'no messages' and modelarmor error
bodies to stderr so stdout stays machine-readable.

Component 2 (PR #466): Add colored error[variant]: labels to stderr
on TTY, respecting NO_COLOR. Replace emoji hint with colorized text.

Component 3 (PR #446): Propagate auth errors as GwsError::Auth in
calendar, chat, docs, drive, script, sheets helpers instead of
silently proceeding unauthenticated. dry-run bypass preserved.
@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2026

🦋 Changeset detected

Latest commit: f4f20a4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@googleworkspace-bot googleworkspace-bot added area: core Core CLI parsing, commands, error handling, utilities cla: yes This human has signed the Contributor License Agreement. and removed area: http labels Mar 17, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request consolidates several improvements focused on enhancing the clarity and utility of output and error handling. The changes ensure that diagnostic information is properly routed to stderr, error messages are more visually distinct and informative, and authentication failures are explicitly reported, leading to a more robust and user-friendly command-line experience.

Highlights

  • Route diagnostics to stderr: Diagnostic messages, such as 'No messages found' in triage.rs and detailed error responses in modelarmor.rs, are now directed to stderr to ensure stdout remains clean for programmatic parsing.
  • Colored error labels: Error messages printed to stderr now include bold, colored labels (e.g., error[api]:, error[auth]:) for improved readability on TTYs, respecting the NO_COLOR environment variable. The accessNotConfigured guidance also uses a hint: prefix.
  • Auth error propagation: Authentication failures across various helpers (calendar, chat, docs, drive, script, sheets) now explicitly propagate as GwsError::Auth instead of silently proceeding without authentication. The --dry-run functionality remains unaffected.
Changelog
  • .changeset/stderr-output-hygiene.md
    • Added a new changeset file documenting the combined changes for stderr/output hygiene, colored error labels, and auth error propagation.
  • src/error.rs
    • Introduced stderr_supports_color function to detect TTY and NO_COLOR environment variable.
    • Added colorize function to apply ANSI bold and color codes conditionally to text.
    • Implemented error_label function to generate colored error prefixes for different GwsError variants.
    • Modified print_error_json to output a colored summary line to stderr for human readability.
    • Updated accessNotConfigured guidance to use a hint: prefix and colorize for better presentation.
    • Added test_colorize_respects_no_color_env to verify NO_COLOR functionality.
    • Added test_error_label_contains_variant_name to ensure correct error label formatting for all variants.
  • src/helpers/calendar.rs
    • Modified authentication error handling to propagate GwsError::Auth on failure, while preserving --dry-run functionality.
  • src/helpers/chat.rs
    • Modified authentication error handling to propagate GwsError::Auth on failure, while preserving --dry-run functionality.
  • src/helpers/docs.rs
    • Modified authentication error handling to propagate GwsError::Auth on failure, while preserving --dry-run functionality.
  • src/helpers/drive.rs
    • Modified authentication error handling to propagate GwsError::Auth on failure, while preserving --dry-run functionality.
  • src/helpers/gmail/triage.rs
    • Rerouted 'No messages found' diagnostic output from stdout to stderr.
    • Extracted the 'No messages found' message into a new no_messages_msg helper function.
    • Added empty_result_message_is_not_json test to ensure diagnostic output is not valid JSON.
  • src/helpers/modelarmor.rs
    • Adjusted the timing of response body printing to occur only on successful API calls.
    • Enhanced error messages for non-success API responses to include the full response body for better diagnostics.
    • Added test_error_path_message_includes_status_and_body to verify the content of error messages.
  • src/helpers/script.rs
    • Modified authentication error handling to propagate GwsError::Auth on failure, while preserving --dry-run functionality.
  • src/helpers/sheets.rs
    • Modified authentication error handling to propagate GwsError::Auth on failure, while preserving --dry-run functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a rollup of several fixes for output and error handling. The changes correctly route diagnostic messages to stderr, add colored error labels, and properly propagate authentication failures instead of failing silently. The code is well-structured and includes relevant tests for the new functionality. I have one suggestion to improve the error output for accessNotConfigured errors to avoid printing redundant information.

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 48.63014% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.10%. Comparing base (1572570) to head (f4f20a4).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/helpers/workflows.rs 0.00% 12 Missing ⚠️
src/error.rs 84.05% 11 Missing ⚠️
src/helpers/gmail/mod.rs 20.00% 8 Missing ⚠️
src/helpers/gmail/watch.rs 0.00% 6 Missing ⚠️
src/helpers/events/subscribe.rs 0.00% 5 Missing ⚠️
src/credential_store.rs 50.00% 4 Missing ⚠️
src/executor.rs 0.00% 4 Missing ⚠️
src/helpers/sheets.rs 0.00% 4 Missing ⚠️
src/token_storage.rs 0.00% 4 Missing ⚠️
src/generate_skills.rs 0.00% 2 Missing ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #525      +/-   ##
==========================================
+ Coverage   67.94%   68.10%   +0.15%     
==========================================
  Files          40       40              
  Lines       17721    17954     +233     
==========================================
+ Hits        12040    12227     +187     
- Misses       5681     5727      +46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 17, 2026
Use if/else so that accessNotConfigured errors get the specialized
hint guidance instead of redundantly printing both the generic summary
and the hint. Non-accessNotConfigured Api errors and all other variants
still get the generic error[variant]: summary line.
@github-actions github-actions bot removed the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 17, 2026
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a rollup of several changes aimed at improving output hygiene. It correctly routes diagnostic messages to stderr, adds colored error labels for better readability, and properly propagates authentication failures instead of letting them fail silently. The changes are well-implemented and include corresponding tests. I've found one high-severity issue in a test that doesn't correctly verify the intended behavior, giving a false sense of security.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 17, 2026
model_armor_post function. A proper integration test would require
HTTP mocking (e.g. mockito/wiremock) which is out of scope for this PR.
@github-actions github-actions bot removed the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 17, 2026
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great rollup of several hygiene improvements for the CLI's output and error handling. The changes to route diagnostics to stderr, add colored error labels, and propagate authentication errors correctly are all valuable enhancements. I've found one area in the error printing logic where code duplication can be removed to improve maintainability, as noted in the specific comment. Overall, this is a solid set of changes.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 17, 2026
Use early return in accessNotConfigured branch so the generic
eprintln! only appears once, eliminating the duplicated else blocks.
@github-actions github-actions bot removed the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 17, 2026
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great rollup of several hygiene improvements. Routing diagnostics to stderr, adding colored error labels, and propagating authentication errors instead of failing silently are all excellent changes that improve the tool's usability and robustness. The changes are well-structured and include relevant tests. I've found one high-severity security issue related to terminal escape injection in the new error printing logic, with a suggestion for a fix.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 17, 2026
Add sanitize_for_terminal() to strip control characters (ANSI escape
sequences, bell, backspace, etc.) from error messages before printing
to stderr, preventing terminal escape injection from API responses.
Newlines and tabs are preserved for readability.

The function is pub(crate) so it can be reused by other modules that
print untrusted content to stderr.
@github-actions github-actions bot removed the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 17, 2026
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a rollup of several improvements to stderr/stdout hygiene and error handling. It correctly routes diagnostic messages to stderr, adds colored error labels for better readability, and critically, fixes authentication error propagation to fail early instead of silently proceeding. The changes are well-implemented and include corresponding tests.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 17, 2026
Apply sanitize_for_terminal() to all 16 remaining eprintln sites
that print unsanitized error strings to stderr. This prevents
terminal escape sequence injection through error messages.

Files updated:
- workflows.rs (4 sites)
- watch.rs (2 sites)
- gmail/mod.rs (3 sites)
- executor.rs (1 site)
- subscribe.rs (1 site)
- token_storage.rs (2 sites)
- credential_store.rs (2 sites)
- setup.rs (1 site)
- generate_skills.rs (1 site)

Also fixes clippy: map_err -> inspect_err where closure only logs.
@github-actions github-actions bot removed the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 17, 2026
@googleworkspace-bot googleworkspace-bot added area: skills area: auth area: http gemini: reviewed Gemini Code Assist has reviewed the latest changes labels Mar 17, 2026
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a rollup of several fixes for output and error handling hygiene. It correctly routes diagnostic messages to stderr, adds colored error labels, propagates authentication errors instead of failing silently, and sanitizes error output for security. The changes are well-implemented across the codebase and improve the tool's usability and robustness. I have reviewed the changes and found no issues.

@jpoehnelt jpoehnelt merged commit 6f92e5b into main Mar 17, 2026
32 checks passed
@jpoehnelt jpoehnelt deleted the fix/stderr-output-hygiene branch March 17, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: auth area: core Core CLI parsing, commands, error handling, utilities area: http area: skills cla: yes This human has signed the Contributor License Agreement. gemini: reviewed Gemini Code Assist has reviewed the latest changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants